package com.mes.service.jy;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mes.dao.jy.PlandetailMapper;
import com.mes.entity.jy.Plandetail;
import com.mes.entity.jy.Queryjy;

/**
 * @ClassName: ProductPlanDetailServiseImpl 
 * @Description:生产计划单详情业务层实现类
 * @Author jy
 * @Date 2017年12月27日 下午2:56:20 
 * @version 1.0
 */
@Service
@Transactional
public class ProductPlanDetailServiseImpl implements ProductPlanDetailServise{

	@Resource
	private PlandetailMapper plandetailMapper;
	
	@Override
	public int createOrupdateDetaile(Plandetail planDetail) {
		//根据生产单号和产品id查询详情表中是否已存在此信息
		Plandetail planDetail2 = plandetailMapper.selectDetailByMany(planDetail);
		
		if(planDetail2 == null) {
			//不存在就新增保存此数据
			return plandetailMapper.createDetaile(planDetail);
		}
			//存在就修改此数据（存在时生产计划单编号和产品id都存在）
			//判断计划量和要求完工日期是否为空
			//如果计划量为空,从查询出的planDetail2中获得计划量，setplanDetail进去
			if(planDetail.getRemartk1().equals(null) || planDetail.getRemartk1().equals("")) {
				planDetail.setRemartk1(planDetail2.getRemartk1());
			}
			if(planDetail.getPwdate().equals(null) || planDetail.getPwdate().equals("")) {
				planDetail.setPwdate(planDetail2.getPwdate());
			}
			return plandetailMapper.updateDetaile(planDetail);
	}

	@Override
	public int countProductPlanDetail(String plannum) {
		return plandetailMapper.countProductPlanDetail(plannum);
	}

	@Override
	public List<Plandetail> selectPlanDetail(String plannum) {
		return plandetailMapper.selectPlanDetail(plannum);
	}

	@Override
	public Plandetail slectPlanDetailByid(Long id) {
		return plandetailMapper.slectPlanDetailByid(id);
	}

	@Override
	public List<Plandetail> selectAllPlanDetail(Queryjy queryjy) {
		return plandetailMapper.selectAllPlanDetail(queryjy);
	}

	@Override
	public int editWstape(Plandetail plandetail) {
		return plandetailMapper.editWstape(plandetail);
	}

	@Override
	public void editDyDetail(Plandetail plandetail) {
		plandetailMapper.editDyDetail(plandetail);
	}

	@Override
	public void editRemark11(Plandetail plandetail) {
		plandetailMapper.editRemark11(plandetail);
	}

	@Override
	public void editDyDetail2() {
		plandetailMapper.editDyDetail2();
	}

	@Override
	public int countProductPlanDetail2(String plannum) {
		return plandetailMapper.countProductPlanDetail2(plannum);
	}

	@Override
	public List<Plandetail> selectPlanDetail2(String plannum) {
		return plandetailMapper.selectPlanDetail2(plannum);
	}

	@Override
	public void deleteNumNotin() {
		plandetailMapper.deleteNumNotin();
	}

	@Override
	public int countProductAllPlanDetailByState(Queryjy queryjy) {
		return plandetailMapper.countProductAllPlanDetailByState(queryjy);
	}

	@Override
	public void editPlanDetailRemark13(Plandetail plandetail) {
		plandetailMapper.editPlanDetailRemark13(plandetail);
	}

}
